var uid, ws;
document.addEventListener('plusready', function(){
	showWating();
	uid = plus.storage.getItem('uid');
	ws = plus.webview.currentWebview();
	console.log(apiRoot+"/home/article/myCollect/uid/"+uid); 
	List();
	$(".edit").on('tap',function(){
		if($(".edit").html()=="操作"){
			$(".edit").html("删除");
		}else{
			var arrId = ',';
			$("input[type='checkbox']:checked").each(function(){
				arrId += $(this).val() + ",";
			})
			console.log(apiRoot+"/home/article/delNews/aid/"+arrId)
			if(arrId != ','){
				showWating();
				$.ajax({
					type:"get",
					url:apiRoot+"/home/article/delNews",
					data:{
						aid :arrId,
						uid :uid
					},
					success :function(data){
						console.log(data);
						plus.nativeUI.closeWaiting();
						if(data > 0){
							toast('删除成功');
							var strs= []; //定义一数组 
							strs = arrId.split(","); //字符分割 
							for (i=0;i<strs.length ;i++ ){ 
								$('.li'+strs[i]).remove();
							} 
							if($('#content li').length < 1){
								$('header span').hide();
							}
						}else{
							plus.nativeUI.closeWaiting();
							toast('删除失败');
						}
					},
					error :function(e){
						console.log(JSON.stringify(e));
					}
				});
			}
			$(".edit").html("操作");
		}
		$(".edit-text").toggle();
	})
}, false)
function List(){
	$.ajax({
		type :"get",
		url :apiRoot+"/home/article/myCollect",
		data :{uid:uid},
		dataType :'json',
		success :function(data){
			plus.nativeUI.closeWaiting();
			if(data.length > 0){
				var list = '';
				$.each(data, function(k, v) {
					list += '<li class="mui-table-view-cell mui-media li'+v.id+'">'+
			        	'<div class="mui-input-row mui-checkbox mui-left edit-text" style="display: none;">'+
							'<input name="checkbox" value="'+v.id+'" type="checkbox" class="aa" >'+
						'</div>'+
			            '<a href="javascript:;" data-id="'+v.id+'">'+
			                '<img class="mui-media-object mui-pull-left" src="'+webRoot+v.litpic+'">'+
			                '<div class="mui-media-body">'+
			                	v.title+
			                    '<p class="mui-ellipsis-2 firstp">'+v.description+'</p>'+
			                '</div>'+
			            '</a>'+
			        '</li>';
				});
				$('#content ul').html(list);
				$('header span').show();
				$('a').unbind('tap');
				$('a').on('tap',function(){
					var id = $(this).attr('data-id');
					goNewPage('jk-new.html',{aid:id, spage:ws.id})
				})
			}else{
				$('#content ul').html('');
				if($('li').length < 1)$(".edit").html("");
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
		}
	});
}
